<?php if (!defined('THINK_PATH')) exit();?>
	<div style='font:normal bold 18px/30px normal;text-align:center;color:#abc'>
		发布信息
	</div>

	<div style='display:flex;margin-top:16px'>
		<div style='flex:3;text-align:right'>类型：</div>		
		<div style='flex:7'>
			<input type='radio' checked='checked' value='1' id='a' name='info_type' class='issue_class'/> 
			<label for='a' >出售</label>
			<input type='radio' value='2' id='b' name='info_type'  class='issue_class'/> 
			<label for='b'>出租</label>
			<input type='radio' value='3' id='c' name='info_type'  class='issue_class'/> 
			<label for='c'>求购</label>
			<input type='radio' value='4' id='d' name='info_type'  class='issue_class'/> 
			<label for='d'>求租</label>
		</div>
	</div>

	<form action='/index.php/Fang/Before/issue_job_c' method='post' id='f_job' >

		<div style='display:flex;margin-top:16px'>
			<div style='flex:3;text-align:right'>标题：</div>		
			<div style='flex:7'>
				<input name='info_title' style='width:70%' />
			</div>
		</div>

		<div style='display:flex;margin-top:16px'>
			<div style='flex:3;text-align:right'>户型：</div>		
			<div style='flex:7'>

				<select id='issue_info_class' name='info_class' style='width:50%'>
					<?php if(is_array($_SESSION['info_class'])): $i = 0; $__LIST__ = $_SESSION['info_class'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i; if($key != 0): ?><option value='<?php echo ($key); ?>'><?php echo ($vo); ?></option><?php endif; endforeach; endif; else: echo "" ;endif; ?>
				</select>

	
			</div>
		</div>

		<div style='display:flex;margin-top:16px'>
			<div style='flex:3;text-align:right'>面积：</div>		
			<div style='flex:7'>
				<input name='info_area' style='width:50%' /> ㎡
			</div>
		</div>

		<div style='display:flex;margin-top:16px'>
			<div style='flex:3;text-align:right'>价格：</div>		
			<div style='flex:7'>
				<input name='info_price' style='width:50%' />
				<span id='issue_input_price_y'>元</span><span id='issue_input_price_wy'>万元</span>
			</div>
		</div>

		<div style='display:flex;margin-top:16px'>
			<div style='flex:3;text-align:right'>地址：</div>		
			<div style='flex:7'>
				<input name='info_addr' style='width:70%' />
			</div>
		</div>

		<div style='display:flex;margin-top:16px'>
			<div style='flex:3;text-align:right'>联系人：</div>		
			<div style='flex:7'>
				<input name='info_contacts' style='width:70%' />
			</div>
		</div>

		<div style='display:flex;margin-top:16px'>
			<div style='flex:3;text-align:right'>联系电话：</div>		
			<div style='flex:7'>
				<input name='info_phone' style='width:70%' />
			</div>
		</div>



		<div style='display:flex;margin-top:16px'>
			<div style='flex:3;text-align:right'>详情描述：</div>		
			<div style='flex:7'>
				<textarea id='info_info' style='width:70%;resize:none'></textarea>
			</div>
		</div>

		<div style='display:flex;margin-top:16px'>
			<div style='flex:3;text-align:right'>图片上传：</div>		
			<div style='flex:7'>
				<div style='border:0px solid;width:70%' id='issue_sess_images'>

				</div>
			</div>
		</div>
		
		<div style='display:flex;margin-top:16px' id='issue_img_add'>
			<div style='flex:3;text-align:right'></div>		
			<div style='flex:7;position:relative'>
				<div style='position:absolute;top:0;left:0;opacity:0;margin-top:0px'>
					<form>
						<input type='file' name='f1' style='width:50px;height:50px;;cursor:pointer' />
					</form>
				</div>
				<img src='/Public/Img/System/upload.png' style='width:50px;height:50px' />
			</div>
		</div>

<script>

	//获取上传的图片列表 
	function get_issue_sess_images(){
		$.ajax({
			url:'/index.php/Fang/Before/issue_sess_images',
			success:function(res){
			//alert(res);
				$('#issue_sess_images').html(res);
			}
		});
	}

	//选择并上传图片
	$('input[name=f1]').change(function(){
	
		var fd = new FormData(document.querySelector('form'));
		fd.append('f_name','f1');
		fd.append('f_path','/imgs/');
		fd.append('token','<?php echo Token_Set('issue_img_add');?>');
		
		//alert(fd);
		$.ajax({
			url:"/index.php/Fang/Before/issue_img_add",
			type:'POST',
			data:fd,
			processData:false,	//是否进行序列化处理
			contentType:false,
			success:function(res){
				//alert(res);
				switch(res){
					case 'e1':
						alert('图片类型不正确');
					break;
					case 'e2':
						alert('图片后缀不正确');
					break;
					case 'e3':
						alert('图片上传失败');
					break;
					case 'ok':
						get_issue_sess_images();
					break;
					case 'e4':
						//alert('上传图片超限！');
						$("#issue_img_add").hide();
						get_issue_sess_images();
					break;
					case 'e5':
						alert('非法访问');
					break;

				}
			}
		});
		get_issue_sess_images();
	});


	$(document).ready(function(){
		$.ajax({
			url:'/index.php/Fang/Before/issue_sesstemp_clear',
			success:function(res){
				//alert(res);
				get_issue_sess_images();
			}
		});
	});
</script>

		
	

		<div style='display:flex;margin-top:55px'>
			<div style='flex:5;text-align:right'>
					<button type='button' id='issue_submit'>提交</button>
			</div>		
			<div style='flex:1'></div>
			<div style='flex:5'>
				<button type='button' id='Issue_Back'>返回</button>
			</div>
		</div>
	</form>
	<div style='margin-bottom:90px'></div>


<script>


	$(function(){
		//--返回按钮
		$('#Issue_Back').click(function(){
			index_init();
		});



		//提交按钮
		$('#issue_submit').click(function(){
			var info_type = $('input[name=info_type]:checked').val();
			var info_title = $('input[name=info_title]').val().trim();
			var info_class = $('#issue_info_class  option:selected').text();
			var info_class_id = $('#issue_info_class  option:selected').val();
			var info_area = $('input[name=info_area]').val().trim();
			var info_price = $('input[name=info_price]').val().trim();
			var info_addr = $('input[name=info_addr]').val().trim();
			var info_contacts = $('input[name=info_contacts]').val().trim();
			var info_phone = $('input[name=info_phone]').val().trim();
			var info_info = $('#info_info').val().trim();

			var p1 = /^.{2,100}$/;
			if(!p1.test(info_title)){
				alert('标题长度不合法!');exit;
			}

			var p2 = /^[1-9]{1,5}[.]?[0-9]{0,2}$/;
			if(!p2.test(info_area)){
				alert('面积输入不合法！');exit;
			}


			if(!sessionStorage.issue_class || sessionStorage.issue_class=='a' || sessionStorage.issue_class == 'c'){
				var p4 = /^[1-9]{1,5}[.]?[0-9]{0,2}$/;
				if(!p4.test(info_price)){
					alert('价格输入不合法！');exit;
				}
			}else{
				var p3 = /^[0-9]{1,5}$/;
				if(!p3.test(info_price)){
					alert('价格输入不合法！');exit;
				}
			}


			var p5 = /^.{1,24}$/;
			if(!p5.test(info_contacts)){
				alert('联系人填写不合法！');exit;
			}


			var p6 = /^[0-9]{7,12}$/;
			if(!p6.test(info_phone)){
				alert('电话填写不正确！');exit;
			}


			var p7 = /^.{0,200}$/;
			if(!p7.test(info_addr)){
				alert('地址长度不合法！');exit;
			}

			var p8 = /^.{0,500}$/;
			if(!p8.test(info_info)){
				alert('详情输入长度不合法！');exit;
			}

			$.ajax({
				url:'/index.php/Fang/Before/issue_c',
				type:'post',
				data:{
					token:'<?php echo Token_Set('issue_c');?>',
					info_title : info_title,
					info_type : info_type,
					info_hClass : info_class,
					info_hClassId : info_class_id,
					info_hArea : info_area,
					info_hPrice : info_price,
					info_addr : info_addr,
					info_contacts : info_contacts,
					info_phone : info_phone,
					info_info : info_info,
					issue_class:sessionStorage.issue_class
				},
				success:function(res){
				//	alert(res);exit;
					switch(res){
						case 'ok':alert('发布成功！');index_init();break;
						case 'e8':alert('同类信息每天只能发布一条！');break;
						default:alert('出现异常！'+res);
					}
				}
			});

			
		});







		issue_price_change();	//根据类型的缓存，初始化类型选项与价格显示 

		//类型的切换
		$('.issue_class').change(function(){
			sessionStorage.issue_class = $(this).attr('id');
			issue_price_change();
		});

	});


	//根据类型的缓存，初始化类型选项与价格显示 
	function issue_price_change(){
		if(!sessionStorage.issue_class || sessionStorage.issue_class=='a' || sessionStorage.issue_class == 'c'){
			$('#issue_input_price_y').hide();
			$('#issue_input_price_wy').show();
		}else{
			$('#issue_input_price_wy').hide();
			$('#issue_input_price_y').show();
		}
		switch(sessionStorage.issue_class){

			case "b":
				$('.issue_class').eq(1).attr('checked','checked');break;
			case "c":
				$('.issue_class').eq(2).attr('checked','checked');break;
			case "d":
				$('.issue_class').eq(3).attr('checked','checked');break;
			default :
				$('.issue_class').eq(0).attr('checked','checked');
		}
	}




</script>